<template>
  <div v-show="menuList.list.length!=0" class="wrapper">
    <app-dialog></app-dialog>
    <app-header></app-header>
    <app-sidebar></app-sidebar>
    <key-board v-if="keyBoard.isShow"></key-board>
    <div class="content-wrapper" :class="{ 'to-full' : isHideSideBar}">
      <app-tab></app-tab>
      <div class="router-wrapper">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { mapGetters, mapMutations, mapState } from "vuex";
import common from "../mixins/common.js";
import Loading from "../components/widgets/Loading.vue";
import Toast from "../components/widgets/Toast.vue";
import Dialog from "../components/widgets/Dialog.vue";
import Header from "../components/Header.vue";
import Sidebar from "../components/Sidebar.vue";
import Tab from "../components/Tab.vue";
import keyboard from "../components/widgets/keyboard.vue";
import { setCookie, getCookie, deleteCookie } from "@/assets/js/storage.js";

export default {
  mixins: [common],
  data() {
    return {
      isDestory: false,
      isShow: true
    };
  },
  computed: {
    ...mapState(["keyBoard"]),
    ...mapGetters({
      isHideSideBar: "getIsHideSideBar",
      menuList: "getAllMenu"
    }),
    ...mapState(["logoObj"])
  },

  components: {
    "app-loading": Loading,
    "app-toast": Toast,
    "app-dialog": Dialog,
    "app-header": Header,
    "app-sidebar": Sidebar,
    "app-tab": Tab,
    "key-board": keyboard
  },
  mounted() {
    this.getSkinConfig();
    this.isShowOperator();
  },
  methods: {
    ...mapMutations(["setLogoObj", "setSkinType"]),
    isShowOperator() {
      let self = this;
      axios.get("/operator/getCurrentOperatorInfo.do").then(
        response => {
          let val = false;
          var returnData = response.data
          if ( returnData && returnData.status == 1 ) {
            if(returnData.data.hasChilds == 1){
              val = true;
            }
            window.sessionStorage.setItem(
              "_operatorID",
              returnData.data.operatorID
            );
          }
          sessionStorage.setItem("isShowOperator", val);
        },
        response => {}
      );
    },
    judgeIsLogin() {
      if (!this.userToken) {
        this.$router.push({
          path: "/"
        });
      }
    },
    getSkinConfig(aparams) {
      let carrierId = window.sessionStorage.getItem("_carrierId") ? window.sessionStorage.getItem("_carrierId") : getCookie("_carrierId");
      let self = this,
        params = {
          carrierId: carrierId
        };
      params = $.extend({}, params, aparams);
      API.login.getSkinConfig(params).then(
        res => {
          let data = res.data;
          self.setSkinType(data.skinTheme);
          self.setLogoObj(data);
        },
        err => {}
      );
    }
  }
};
</script>

<style lang="less">
@import "../assets/less/base/flex.less";
</style>